﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SolutionBLL;
using SolutionModel;
using SFast.DB;
using SFast;

public partial class admin_system_RolesList : System.Web.UI.Page
{

    T_AdminRolesBLL bll = new T_AdminRolesBLL();

    protected void Page_Load(object sender, EventArgs e)
    {
        //Pagination<T_AdminRole> list = bll.GetAdminRolesList(10);
        //rp_list.DataSource = list;
        //rp_list.DataBind();
        //div_page.InnerHtml = list._ToPageHtml();

    }

    public String getRoleList()
    {
        Pagination<T_AdminRole> list = bll.GetAdminRolesList(15);
        String jsonStr = list._ToJsonStr();
        return jsonStr;
    }

    public String getMenuTrr()
    {
        T_MenuBLL bll = new T_MenuBLL();
        String jsonStr = bll.GetTree()._ToJsonStr();
        jsonStr = jsonStr.Replace("ID", "id").Replace("Name", "text");
        return jsonStr;
    }

    public String updateMenu()
    {
        MessageInfoByFormModel mesInfo = new MessageInfoByFormModel();
        String roleId = Request["roleId"];
        String menuIds = Request["menuIds"];
        
        if (!roleId._HasVal())
        {
            mesInfo.info = "保存成功！";
            mesInfo.status = "y";
            return mesInfo._ToJsonStr();
        }
        List<int> list_menuIds = new List<int>();
        menuIds = menuIds.TrimEnd(',');
        if (menuIds._HasVal())
        {
            menuIds.Split(',').ForEach(o =>
            {
                list_menuIds.Add(Convert.ToInt32(o));
            });
        }
        T_MenuInRoleBLL mirbll = new T_MenuInRoleBLL();
        //保存信息
        mirbll.InsertOrUpdate(roleId, list_menuIds);
        mesInfo.info = "保存成功！";
        mesInfo.status = "y";
        return mesInfo._ToJsonStr();
    }
}